#encoding=utf8
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
from sklearn import svm
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.naive_bayes import GaussianNB, MultinomialNB, BernoulliNB
from sklearn.neighbors import KNeighborsClassifier
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler, MinMaxScaler, PolynomialFeatures

if __name__ == "__main__":
    train = pd.read_csv('../dataset/train_modified.csv')
    target = 'Disbursed'
    IDcol = 'ID'
    x_columns = [x for x in train.columns if x not in [target, IDcol]]
    X = train[x_columns]
    y = train['Disbursed']
    x_train, x_test, y_train, y_test = train_test_split(X, y, train_size=0.7, random_state=1)

    priors = np.logspace(0,1,len(np.unique(y)))
    print np.unique(y)
    priors /= priors.sum()
    gnb = Pipeline([
        ('sc', StandardScaler()),
        ('poly', PolynomialFeatures(degree=1)),
        ('clf', BernoulliNB())])
    # gnb = KNeighborsClassifier(n_neighbors=3)

    gnb.fit(x_train, y_train.ravel())
    y_hat = gnb.predict(x_train)
    print '训练集准确度: %.3f%%' % (100 * accuracy_score(y_train, y_hat))
    y_test_hat = gnb.predict(x_test)
    print '测试集准确度：%.3f%%' % (100 * accuracy_score(y_test, y_test_hat))